package codingStudy.netEase2018Spring;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author zcxv
 * @category 消除重复元素
 */
public class RemoveRepeatElement {

	static List slove(int N, int[] arr) {
		// 1.通过堆排序算法将arr数组进行排序，时间复杂度为logn
		// 2.遍历经过处理的数组，去除重复

		int[] vars = heapSort(arr, N);
		List<Integer> result = removeReported(vars);
		return result;
	}

	// 手写堆排序，对原始数组进行升序处理
	static int[] heapSort(int[] t, int N) {
		int n = N + 1;
		int[] a = new int[n];
		for (int x = 0; x < N; x++) {
			a[x + 1] = t[x];
		}
		// 1.堆有序
		for (int k = N / 2; k > 0; k--) {
			sink(a, k, N);
		}
		// 2.排序
		int i = N;
		while (i > 1) {
			int m = a[1];
			a[1] = a[i];
			a[i] = m;
			i--;
			sink(a, 1, i);
		}
		return a;

	}

	/**
	 * @param a
	 * @param k
	 * @param n最大下标
	 */
	static void sink(int[] a, int k, int n) {
		while (2 * k <= n) {
			int j = 2 * k;
			if (j < n && a[j] < a[j + 1])
				j++;
			if (a[k] >= a[j])
				break;
			int m = a[k];
			a[k] = a[j];
			a[j] = m;
			k = j;
		}
	}

	// 去除重复
	static List<Integer> removeReported(int[] t) {
		List<Integer> result = new ArrayList<Integer>();
		int j = 2;
		result.add(t[1]);
		while (j < t.length) {
			if (t[j - 1] != t[j]) {
				result.add(t[j]);
				j++;
			} else {
				j++;
			}
		}
		return result;
	}

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		System.out.println(slove(a.length, a));
		scanner.close();


	}
}